<template>
  <div class="transQuery_main">
    <a-form>
      <a-row :gutter="16" style="margin-left: 0; margin-right: 0">
        <!-- <a-col :span="4">
          <a-form-item>
            <a-input placeholder="商户单号" v-model="query.data.merchantOrderNo" />
          </a-form-item>
        </a-col>-->
        <a-col :span="4" style="padding: 0">
          <a-form-item>
            <a-input
              placeholder="客户名称"
              v-model="query.data.mainMemberName"
            />
          </a-form-item>
        </a-col>
        <a-col :span="4" style="padding: 0" :offset="1">
          <a-form-item>
            <a-input placeholder="终端号" v-model="query.data.snCode" />
          </a-form-item>
        </a-col>
        <a-col :span="4" style="padding: 0" :offset="1">
          <a-form-item>
            <a-input
              placeholder="卡号后四位"
              v-model="query.data.externalAccountNo"
            />
          </a-form-item>
        </a-col>
        <a-col :span="4" style="padding: 0" :offset="1">
          <a-form-item>
            <a-input placeholder="合作机构号" v-model="query.data.agentCode" />
          </a-form-item>
        </a-col>
        <a-col :span="4" :offset="1">
          <a-form-item>
            <a-select
              placeholder="交易类型"
              :options="transTypeList"
              v-model="query.data.transCode"
            ></a-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="16" style="margin-left: 0; margin-right: 0">
        <a-col :span="4" style="padding: 0">
          <a-form-item>
            <a-select
              placeholder="交易状态"
              :options="statusList"
              v-model="query.data.status"
            ></a-select>
          </a-form-item>
        </a-col>
        <!-- <a-col :span="4" :offset='1'>
          <a-form-item>
            <a-select placeholder="结算状态" :options="SettleStatusList" v-model="query.data.settleStatus"></a-select>
          </a-form-item>
        </a-col>-->
        <a-col :span="8" :offset="1" style="padding: 0">
          <a-form-item>
            <!-- <a-date-picker
              style="width: 100%"
              placeholder="交易时间"
              format="YYYYMMDD"
              @change="onChange"
              v-model="momentDate"
              :allowClear="isClear"
            /> -->
            <a-range-picker
              :disabledDate="disabledDate"
              @change="onChange"
              format="YYYYMMDD"
              v-model="momentDate"
            />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row style="margin-bottom: 20px">
        <a-col :span="9" :style="{ textAlign: 'left' }">
          <a-row type="flex" justify="space-between">
            <a-col :span="6">
              <a-button
                class="button_sty"
                type="primary"
                :loading="loading"
                @click="handleSearch(1)"
                >查询</a-button
              >
            </a-col>
            <a-col :span="6">
              <a-button class="button_sty" type="primary" @click="reset"
                >重置</a-button
              >
            </a-col>
            <!-- <a-col :span="6">
              <a-button class="button_sty" type="primary" @click="conexport">导出</a-button>
            </a-col>-->
          </a-row>
        </a-col>
      </a-row>
    </a-form>
    <p style="text-align: right">
      交易<span class="amountColor amountSize">{{ count }}</span
      >笔 &nbsp;金额<span class="amountColor amountSize">{{
        (amount / 100).toFixed(2)
      }}</span
      >元
    </p>
    <a-table
      size="middle"
      :scroll="{ y: '38vh' }"
      :columns="columns"
      :dataSource="list"
      :pagination="false"
      :rowKey="(record) => record.transOrderNo"
    >
      <!-- :expandRowByClick='true' -->
      <!-- <div slot="expandedRowRender" slot-scope="record" class="expand">
        <span style='margin-right:15px;'>交易单号：<span class="amountColor">{{record.transOrderNo}}</span></span>
        <span style='margin-right:15px;'>交易手续费：<span class="amountColor">{{record.feeAmount.toFixed(2)}}元</span></span>
        <span style='margin-right:15px;'>D0服务费：<span class="amountColor">{{record.d0SingleAmount}}元</span></span>
        {{record.description}}
      </div>-->
      <span slot="externalAccountNo" slot-scope="record"> 
        <span v-if="sensitive=='1'">
          {{record.externalAccountNo | AccountNofilter}}
        </span>
        <span v-if="sensitive=='0'">
          {{record.externalAccountNo }}
        </span>
      </span>
      <span slot="transTime" slot-scope="record">{{
        record.transTime | timeFilter
      }}</span>
      <span slot="amount" slot-scope="record">{{
        (record.amount / 100).toFixed(2)
      }}</span>
      <span slot="action" slot-scope="record">
        <span
          @click="goDetail(record.transOrderNo, record.type)"
          style="color: #1890ff"
          >详细</span
        >
      </span>
    </a-table>
    <a-pagination
      @change="onPageChange"
      :current="pagination.current"
      :total="pagination.total"
      :pageSize="query.pageSize"
      style="margin-top: 50px"
    />
  </div>
</template>

<script>
import AForm from "ant-design-vue/es/form/Form";
import ATabs from "ant-design-vue/es/tabs";
import AFormItem from "ant-design-vue/es/form/FormItem";
import AInput from "ant-design-vue/es/input/Input";
import AIcon from "ant-design-vue/es/icon";
import AInputGroup from "ant-design-vue/es/input/Group";
import AButton from "ant-design-vue/es/button/button";
import ACol from "ant-design-vue/es/grid/Col";
import ARow from "ant-design-vue/es/grid/Row";
import ACheckbox from "ant-design-vue/es/checkbox/Checkbox";
import AAlert from "ant-design-vue/es/alert/index";
import moment from "moment";
import api from "@/common/api";
const ATabPane = ATabs.TabPane;

const columns = [
  {
    title: "客户名称",
    dataIndex: "mainMemberName",
    width: "10%",
    align: "center",
  },
  {
    title: "交易卡号",
  
    width: "10%",
    align: "center",
     scopedSlots: { customRender: "externalAccountNo" },
  },
  { title: "交易日期", dataIndex: "transDate", width: "10%", align: "center" },
  {
    title: "交易时间",
    scopedSlots: { customRender: "transTime" },
    width: "10%",
    align: "center",
  },
  {
    title: "交易单号",
    dataIndex: "transOrderNo",
    width: "20%",
    align: "center",
  },
  {
    title: "交易金额",
    scopedSlots: { customRender: "amount" },
    width: "10%",
    align: "center",
  },
  { title: "交易类型", dataIndex: "transName", width: "11%", align: "center" },
  { title: "交易状态", dataIndex: "statusName", width: "11%", align: "center" },
  // { title: "结算状态", dataIndex: "settleStatus", width: '11%', align: 'center' },
  {
    title: "操作",
    scopedSlots: { customRender: "action" },
    width: "8%",
    align: "center",
  },
];

export default {
  name: "Login",
  components: {
    AAlert,
    ACheckbox,
    ACol,
    ARow,
    AButton,
    AInputGroup,
    AIcon,
    AInput,
    AFormItem,
    ATabPane,
    ATabs,
    AForm,
  },

  data() {
    return {
      today: new Date(),
      columns,
      isClear: false,
      momentDate: null,
      excelurl: "",
      statusList: [
        // { label: "全部", value: "all" },
        // { label: "交易成功", value: "payed" },
        // { label: "交易失败", value: "failed" },
        // { label: "待支付", value: "ordered" },
      ],
      SettleStatusList: [],
      transTypeList: [
        // { label: "全部", value: "all" },
        // { label: "消费", value: "pay" },
      ],
      query: {
        data: {
          transCode: "all",
          settleStatus: "all",
          status: "all",
          agentCode: null,
          startDate: "",
          endDate: "",
          externalAccountNo: "",
          snCode: "",
          mainMemberName: "",
        },
        page: 1,
        pageSize: 10,
      },
      amount: 0,
      count: 0,
      pagination: { current: null, total: null },
      visible: false,
      form: this.$form.createForm(this),
      error: "",
      loginpwd: "",
      loginpwd2: "",
      login: false,
      list: [],
      count: null,
      payedCount: null,
      totalAmount: null,
      loading: false,
      formItemLayout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 14, offset: 1 },
          md: { span: 14, offset: 1 },
        },
      },
      sensitive: localStorage.getItem("sensitive"),
    };
  },
  watch: {},
  filters: {
    timeFilter: function (value) {
      if (value) {
        let year = value.substring(0, 2);
        let mouth = value.substring(2, 4);
        let day = value.substring(4, 6);
        return year + ":" + mouth + ":" + day;
      }
    },
  },
  computed: {},
  created() {},
  mounted() {
    this.handleSearch(1);
    this.transTypeQuery();
    this.statusQuery();
    // this.SettleStatusQuery();
    // var date = new Date();
    // var month = date.getMonth();
    // var dates = date.getDate();
    // if (date.getMonth() < 9) {
    //   month = "0" + parseInt(month + 1);
    // } else {
    //   month = month + 1;
    // }
    // if (date.getDate() <= 9) {
    //   dates = "0" + date.getDate();
    // }
    // console.log("dates", dates);
    // this.query.data.transDate = date.getFullYear() + "" + month + "" + dates;
  },
  methods: {
    moment,
    onPageChange: function (page, pageSize) {
      console.info(page, pageSize);
      this.query.page = page;
      this.query.pageSize = pageSize;
      this.handleSearch(page);
    },
    disabledDate(current) {
      return current > moment().subtract(0, "day");
    },
    onChange(date, dateString) {
      console.log(date, dateString);
      this.query.data.startDate = dateString[0];
      this.query.data.endDate = dateString[1];
    },
    reset() {
      this.query.data = {
        agentCode: null,
        transCode: "all",
        settleStatus: "all",
        status: "all",
        externalAccountNo: "",
        snCode: "",
        mainMemberName: "",
        startDate: "",
        endDate: "",
      };
      this.momentDate = null;
      // var date = new Date();
      // this.momentDate = moment(date);
      // var month = date.getMonth();
      // var dates = date.getDate();
      // if (date.getMonth() < 9) {
      //   month = "0" + parseInt(month + 1);
      // } else {
      //   month = month + 1;
      // }
      // if (date.getDate() <= 9) {
      //   dates = "0" + date.getDate();
      // }
      // this.query.data.transDate = date.getFullYear() + "" + month + "" + dates;
    }, //重置
    conexport() {
      console.info(this.query.data);
      this.$axios
        .post("/agent/transaction/fetchExportQuery", this.query.data)
        .then((res) => {
          let token = localStorage.getItem("token");
          let downloadUrl =
            "/agent/transaction/excelDownloadTrans?Authorization=" + token;
          location.href = downloadUrl;
        });
    },
    protocolstatus() {
      //此方法是用来填充状态的
      this.$axios.get("/agent/transaction/protocolList").then((res) => {
        console.info(res);
        this.transTypeList = [];
        this.transTypeList.push({ label: "全部", value: "all" });
        for (var i = 0; i < res.data.list.length; i++) {
          this.transTypeList.push({
            label: res.data.list[i].transName,
            value: res.data.list[i].transCode,
          });
        }
      });
    },
    // 交易类型查询
    transTypeQuery() {
      let data = {
        groupCode: "posp_trans_type",
      };
      api.statusQuery(
        data,
        (res) => {
          console.log(res);
          if (res.code == "OK") {
            let statusList = res.list;
            this.transTypeList = [{ value: "all", label: "全部" }];
            statusList.forEach((item, index) => {
              let itemList = {
                value: item.value,
                label: item.label,
              };
              this.transTypeList.push(itemList);
            });
          } else {
          }
        },
        (err) => {}
      );
    },
    //交易状态查询
    statusQuery() {
      let data = {
        groupCode: "posp_trans_status",
      };
      api.statusQuery(
        data,
        (res) => {
          console.log(res);
          if (res.code == "OK") {
            this.statusList = [];
            let statusList = res.list;
            this.statusList = [{ value: "all", label: "全部" }];
            statusList.forEach((item, index) => {
              let itemList = {
                value: item.value,
                label: item.label,
              };
              this.statusList.push(itemList);
            });
          } else {
          }
        },
        (err) => {}
      );
    },
    //结算状态查询
    SettleStatusQuery() {
      let data = {
        groupCode: "offline_settle_status",
      };
      api.statusQuery(
        data,
        (res) => {
          console.log(res);
          if (res.code == "OK") {
            let statusList = res.list;
            this.SettleStatusList = [{ value: "all", label: "全部" }];
            statusList.forEach((item, index) => {
              let itemList = {
                value: item.paramKey,
                label: item.paramValue,
              };
              this.SettleStatusList.push(itemList);
            });
          } else {
          }
        },
        (err) => {}
      );
    },

    handleSearch(value) {
      this.query.page = value;
      this.loading = true;
      console.info(this.query);
      api.coustromOrg(
        this.query,
        (res) => {
          console.info(res);
          if (res.code == "OK") {
            this.loading = false;
            this.list = res.data.listResponse;
            this.list.forEach(function (item) {
              item.amount = item.amount.toFixed(2);
            });
            this.pagination.current = res.data.current;
            this.pagination.total = res.data.total;
            this.count = res.data.count; //总笔数
            // this.payedCount = res.payedCount; //成功笔数
            this.amount = res.data.amount.toFixed(2); //总金额
          } else {
            this.loading = false;
            // this.$message.info(res.message)
            this.list = [];
            this.count = 0;
            this.amount = 0;
            this.pagination.current = 1;
            this.pagination.total = 1;
            return false;
          }
        },
        (err) => {
          console.log("err", err);
          if (err) {
            this.loading = false;
          }
        }
      );
    },
    goDetail(id, type) {
      if (type == "qrcode") {
        this.$router.push(`/org/transmanage/${id}/qrcodedetail`); // 二维码
      } else if (type == "pos") {
        this.$router.push(`/org/transmanage/${id}/transquerydetail`); //pos
      } else if (type == "refund") {
        this.$router.push(`/org/transmanage/${id}/qrcoderefund`); // 退货
      } else if (type == "unionpay.qrcode") {
        this.$router.push(`/org/transmanage/${id}/Unionpayqrcodedetail`);
      }
      // console.log(id);
    },
  },
};
</script>

<style lang="less" scoped>
span {
  cursor: pointer;
}

span {
  cursor: pointer;
}

.formGroupTitle {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
}

.ant-tabs-nav {
  float: right;
}

.amountColor {
  color: #29a576;
  font-weight: 400;
}

.amountSize {
  font-size: 20px;
  padding: 0 5px;
}

.expand {
  display: flex;
  align-items: center;
  justify-content: center;
}

.transQuery_main {
  /* padding: 30px 40px; */
  padding: 70px;
  background: #fff;
}

.button_sty {
  width: 100%;
}
</style>